package cn.wolfcode.producer._02_mode;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

/**
 * 同步的方式发送请求
 * 只有收到成功发送的信息才会继续发送
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        //1.创建生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("wolfcode_producer");
        //2.设置nameSrv地址
        producer.setNamesrvAddr("127.0.0.1:9876");
        //3.启动生产者
        producer.start();
        //发送一百条消息
        for (int i=0; i < 100; i++) {
            //4.设置发送的消息(默认是同步消息)
            Message message = new Message("02_mode","你好啊rocketMQ".getBytes());
            //5.生产者对象发送消息
            SendResult send = producer.send(message);
            System.out.println(send.getMsgId());
            System.out.println(send.getSendStatus());
        }
        //6.关闭连接
        producer.shutdown();
    }
}
